package com.engine4cloud.tdf.admin.api.feign;

import com.engine4cloud.tdf.admin.api.dto.SysFileDownloadRequestDTO;
import com.engine4cloud.tdf.admin.api.dto.SysFileUploadRequestDTO;
import com.engine4cloud.tdf.admin.api.dto.SysFileUploadResultDTO;
import com.engine4cloud.tdf.common.core.constant.SecurityConstants;
import com.engine4cloud.tdf.common.core.constant.ServiceNameConstants;
import com.engine4cloud.tdf.common.core.util.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.support.AbstractFormWriter;
import org.springframework.cloud.openfeign.support.JsonFormWriter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件读取
 *
 * @author tdf
 * @date 2024/3/14
 */
@FeignClient(contextId = "remoteFileService", value = ServiceNameConstants.SYS_SERVICE, configuration = RemoteFileService.MultipartSupportConfig.class)
public interface RemoteFileService {

	/**
	 * 使用多参数
	 */
	@Configuration
	class MultipartSupportConfig {
		@Bean
		public AbstractFormWriter jsonFormWriter() {
			return new JsonFormWriter();
		}
	}

	@PostMapping("/sys-file/oss/file/byte")
	R<byte[]> fileBytes(@RequestBody SysFileDownloadRequestDTO dto, @RequestHeader(SecurityConstants.FROM) String from);

	@PostMapping(value = "/sys-file/uploads", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
	R<SysFileUploadResultDTO> uploads(@RequestPart("file") MultipartFile file, @RequestPart("dto") SysFileUploadRequestDTO dto, @RequestHeader(SecurityConstants.FROM) String from);
}